package com.base.common.job;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.base.common.enums.MeetingStatus;
import com.base.common.persistent.dao.MeetingMapper;
import com.base.common.persistent.model.Meeting;

@Component("meetingStatusChangeJob")
public class MeetingStatusChangeJob {
	Logger log = Logger.getLogger(MeetingStatusChangeJob.class);
	
	@Resource
	private MeetingMapper meetingMapper;
	
	@Scheduled(initialDelay=0, fixedRate=30000)
	public void doMeetingChangeStartJob() {
		List<Meeting> meetings = meetingMapper.queryUotBeginningMeetingInHalfHour();
		log.info("将要开始会议数量：" + meetings.size());
		if(meetings.size() > 0){
			for(Meeting meeting : meetings) {
				int result = meetingMapper.updateStatusById(meeting.getId(), MeetingStatus.UNDERWAY.getValue());
				log.info("会议状态更新结果：" + result);
			}
		}
//		System.out.println("更改会议状态---任务调度中");
	}
	
	@Scheduled(initialDelay=0, fixedRate=30000)
	public void doMeetingChangeEndJob() {
		List<Meeting> meetings = meetingMapper.queryFinishedMeeting();
		log.info("结束会议数量：" + meetings.size());
		if(meetings.size() > 0){
			for(Meeting meeting : meetings) {
				int result = meetingMapper.updateStatusById(meeting.getId(), MeetingStatus.FINISHED.getValue());
				log.info("会议状态更新结果：" + result);
			}
		}
	}
}
